#include "HTTPRequest.h"

namespace qy
{

HTTPRequest::HTTPRequest(const std::string &method, const URI &requestURI, const std::string &httpVersion)
	:m_method(method), m_requestURI(requestURI)
{
	m_httpVersion = "HTTP/" + httpVersion;
	if(httpVersion == "1.1")
	{
		setHeader("host", requestURI.host());	
	}
}

HTTPRequest::~HTTPRequest()
{
}

void HTTPRequest::setHeader(const std::string &name, const std::string  &value)
{
	m_header[name] = value;
}

std::string  HTTPRequest::requestLine()
{
	return m_method + " " + m_requestURI.fullPath() + " " + m_httpVersion + "\r\n";
}

std::string  HTTPRequest::header()
{
	std::string result;
	std::map<std::string, std::string>::const_iterator it;
	for(it = m_header.begin(); it != m_header.end(); it++)
	{
		result += it->first + " : " + it->second + "\r\n";
	}
	return result;
}

void HTTPRequest::getData(char **data, size_t *len)
{
	
}

}
